<?php
defined('IN_MAIN') or exit('Invalid Access!');

function format_prod_display($prods, $delivery_cost){
/*
This function format the $prods into bordered table with info refno, title (sub-product if jumpstart), pv, qty, total pv, grand total pv
input $prods must have the format
$prods[index][refno]
$prods[index][prod_type]
$prods[index][title]
$prods[index][pv]
$prods[index][qty]
*/

	global $vars;

	$td_style="style='border:1px solid black; padding: 3px;'";
	$td_right_style=substr($td_style, 0, strlen($td_style)-1)." text-align:right;'";
	$td_center_style=substr($td_style, 0, strlen($td_style)-1)." text-align:center;'";
	$th_style="style='border:1px solid black; background: #888; padding: 3px; font-weight:bold;'";
	$th_right_style=substr($th_style, 0, strlen($th_style)-1)." text-align:right;'";
	for($i=0,$t=count($prods);$i<$t;$i++){
		if($prods[$i]["prod_type"]=="p"){
			$pck_prods='';
			for($j=0,$t2=count($prods[$i]["pck_prod"]);$j<$t2;$j++){
				$pck_prods.="&nbsp;&nbsp;".$prods[$i]["pck_prod"][$j]["refno"].", ".$prods[$i]["pck_prod"][$j]["title"].", ".__("Qty").__(":")." ".$prods[$i]["pck_prod"][$j]["qty"]."<br />\n";
			}
		}
		$prod_row.="
		<tr>
			<td $td_style>".$prods[$i]["refno"]."</td>
			<td $td_style>".$prods[$i]["title"].($prods[$i]["prod_type"]=="p"? "<br />\n$pck_prods" : "")."</td>
			<td $td_right_style>".number_format($prods[$i]["bv"], 2)."</td>
			<td $td_right_style>".number_format($prods[$i]["dp"], 2)."</td>
			<td $td_right_style>".number_format($prods[$i]["rp"], 2)."</td>
			<td $td_center_style>".$prods[$i]["qty"]."</td>
			<td $td_right_style>".number_format($prods[$i]["bv"] * $prods[$i]["qty"], 2)."</td>
			<td $td_right_style>".number_format($prods[$i]["dp"] * $prods[$i]["qty"], 2)."</td>
			<td $td_right_style>".number_format($prods[$i]["rp"] * $prods[$i]["qty"], 2)."</td>
		</tr>";
		$grand_bv += $prods[$i]["bv"] * $prods[$i]["qty"];
		$grand_dp += $prods[$i]["dp"] * $prods[$i]["qty"];
		$grand_rp += $prods[$i]["rp"] * $prods[$i]["qty"];
	}
	$formatted_prod=
	"<table style='width:600px; border-collapse:collapse; font-family:arial; font-size:12px;'>
		<tr>
			<th $th_style>".__("Ref #")."</th>
			<th $th_style>".__("Title")."</th>
			<th $th_style>BV</th>
			<th $th_style>DP</th>
			<th $th_style>CP</th>
			<th $th_style>".__("Qty")."</th>
			<th $th_style>".replace_tag(__("Total <%title%>"), array("<%title%>"=>__($vars["bv_title"])))."</th>
			<th $th_style>".replace_tag(__("Total <%title%>"), array("<%title%>"=>__("DP")))."</th>
			<th $th_style>".replace_tag(__("Total <%title%>"), array("<%title%>"=>__("CP")))."</th>
		</tr>
		$prod_row
		<tr>
			<td colspan='6' $th_right_style>".__("Delivery Cost")."</td>
			<td $th_right_style>".number_format(0, 2)."</td>
			<td $th_right_style>".number_format($delivery_cost, 2)."</td>
			<td $th_right_style>".number_format($delivery_cost, 2)."</td>
		</tr>
		<tr>
			<td colspan='6' $th_right_style>".__("Order Total")."</td>
			<td $th_right_style>".number_format($grand_bv, 2)."</td>
			<td $th_right_style>".number_format($grand_dp + $delivery_cost, 2)."</td>
			<td $th_right_style>".number_format($grand_rp + $delivery_cost, 2)."</td>
		</tr>
	</table>";

	return $formatted_prod;
}
function format_prod_display2($prods){	global $vars;	$td_style="style='border:1px solid black; padding: 3px;'";	$td_right_style=substr($td_style, 0, strlen($td_style)-1)." text-align:right;'";	$td_center_style=substr($td_style, 0, strlen($td_style)-1)." text-align:center;'";	$th_style="style='border:1px solid black; background: #888; padding: 3px; font-weight:bold;'";	$th_right_style=substr($th_style, 0, strlen($th_style)-1)." text-align:right;'";	for($i=0,$t=count($prods);$i<$t;$i++){		if($prods[$i]["prod_type"]=="p"){			$pck_prods='';			for($j=0,$t2=count($prods[$i]["pck_prod"]);$j<$t2;$j++){				$pck_prods.="&nbsp;&nbsp;".$prods[$i]["pck_prod"][$j]["title"].", ".__("Qty").__(":")." ".$prods[$i]["pck_prod"][$j]["qty"]."<br />\n";			}		}		$prod_row.="		<tr>			<td $td_style>".$prods[$i]["title"].($prods[$i]["prod_type"]=="p"? "<br />\n$pck_prods" : "")."</td>			<td $td_right_style>".number_format($prods[$i]["total_bv"], 2)."</td>			<td $td_right_style>".number_format($prods[$i]["share_price"], 2)."</td>			<td $td_right_style>".number_format(floor($prods[$i]["total_bv"]/$prods[$i]["share_price"]), 0)."</td>			<td $td_right_style>".number_format($prods[$i]["total_bv"] * $prods[$i]["qty"], 2)."</td>		</tr>";		$grand_bv += $prods[$i]["bv"] * $prods[$i]["qty"];	}	$formatted_prod=	"<table style='width:600px; border-collapse:collapse; font-family:arial; font-size:12px;'>		<tr>			<th $th_style>".__("Title")."</th>			<th $th_style>".__("BV")."</th>			<th $th_style>".__("Share Price")."</th>			<th $th_style>".__("Shares Quantity")."</th>			<th $th_style>".replace_tag(__("Total <%title%>"), array("<%title%>"=>__("Amount")))."</th>		</tr>		$prod_row		<tr>			<td colspan='4' $th_right_style>".__("Order Total")."</td>			<td $th_right_style>".number_format($grand_bv, 2)."</td>		</tr>	</table>";	return $formatted_prod;}

function format_prod_display_member($prods, $delivery_cost){
/*
This function format the $prods into bordered table with info refno, title (sub-product if jumpstart), pv, qty, total pv, grand total pv
input $prods must have the format
$prods[index][refno]
$prods[index][prod_type]
$prods[index][title]
$prods[index][pv]
$prods[index][qty]

using the css style for members only
*/

	global $vars;

	for($i=0,$t=count($prods);$i<$t;$i++){
		if($prods[$i]["prod_type"]=="p"){
			$pck_prods='';
			for($j=0,$t2=count($prods[$i]["pck_prod"]);$j<$t2;$j++){
				$pck_prods.="&nbsp;&nbsp;".$prods[$i]["pck_prod"][$j]["refno"].", ".$prods[$i]["pck_prod"][$j]["title"].", ".__("Qty").__(":")." ".$prods[$i]["pck_prod"][$j]["qty"]."<br />\n";
			}
		}
		$prod_row.="
		<tr>
			<td class='center'>".$prods[$i]["refno"]."</td>
			<td>".$prods[$i]["title"].($prods[$i]["prod_type"]=="p"? "<br />\n$pck_prods" : "")."</td>
			<td class='number'>".number_format($prods[$i]["bv"], 2)."</td>
			<td class='number'>".number_format($prods[$i]["dp"], 2)."</td>
			<td class='center'>".$prods[$i]["qty"]."</td>
			<td class='number'>".number_format($prods[$i]["bv"] * $prods[$i]["qty"], 2)."</td>
			<td class='number'>".number_format($prods[$i]["dp"] * $prods[$i]["qty"], 2)."</td>
		</tr>";
		$grand_bv += $prods[$i]["bv"] * $prods[$i]["qty"];
		$grand_dp += $prods[$i]["dp"] * $prods[$i]["qty"];
		$grand_rp += $prods[$i]["rp"] * $prods[$i]["qty"];
	}
	$formatted_prod=
	"<table class='formatted_prod'>
		<tr>
			<th>".__("Ref #")."</th>
			<th>".__("Title")."</th>
			<th>".__("BV")."</th>
			<th>".__("DP")."</th>
			<th>".__("Qty")."</th>
			<th>".replace_tag(__("Total <%title%>"), array("<%title%>"=>__($vars["bv_title"])))."</th>
			<th>".replace_tag(__("Total <%title%>"), array("<%title%>"=>__("DP")))."</th>
		</tr>
	$prod_row
		<tr>
			<td colspan='5' class='bold right'>".__("Delivery Cost")."</td>
			<td class='bold number'>".number_format($delivery_cost, 2)."</td>
			<td class='bold number'>".number_format($delivery_cost, 2)."</td>
		</tr>
		<tr>
			<td colspan='5' class='bold right'>".__("Grand Total")."</td>
			<td class='bold number'>".number_format($grand_bv + $delivery_cost, 2)."</td>
			<td class='bold number'>".number_format($grand_dp + $delivery_cost, 2)."</td>
		</tr>
	</table>";

	return $formatted_prod;
}
?>